package com.gpframework.module.wages.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.gpframework.common.core.domain.entity.SysDept;
import com.gpframework.module.system.mapper.SysDeptMapper;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gpframework.module.wages.mapper.GzAssessSalaryMapper;
import com.gpframework.module.wages.domain.GzAssessSalary;
import com.gpframework.module.wages.domain.vo.GzAssessSalaryVo;
import com.gpframework.module.wages.service.IGzAssessSalaryService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @ClassName GzAssessSalary
 * @Author gpframework
 * @Date 2024-01-18
 * @Version 1.0.0
 * @Description 评定工资Service业务层处理
 */
@Service
public class GzAssessSalaryServiceImpl extends ServiceImpl<GzAssessSalaryMapper, GzAssessSalary> implements IGzAssessSalaryService {


    @Resource
    private SysDeptMapper  sysDeptMapper;
    /**
     * @Description 查询列表返回VO 用于返回给前端的列表接口
     * @Author gpframework
     * @Date 2024-01-18
     * @Param [lqw]
     * @Return List<GzAssessSalaryVo>
     */
    @Override
    public List<GzAssessSalaryVo> listVo(QueryWrapper<GzAssessSalary> lqw) {
        List<GzAssessSalaryVo> gzAssessSalaryVos =this.baseMapper.listVo(lqw);
        List<Long> longList=gzAssessSalaryVos.stream().map(gzAssessSalaryVo ->gzAssessSalaryVo.getDeptId()==null?null:gzAssessSalaryVo.getDeptId()).collect(Collectors.toList());
        if (CollUtil.isNotEmpty(longList)){
            List<SysDept> sysDeptList=sysDeptMapper.selectDepts(longList.stream().distinct().collect(Collectors.toList()));
            if (CollUtil.isNotEmpty(sysDeptList)){
                Map<Long,String> longStringMap=sysDeptList.stream().collect(HashMap::new, (x, y) -> x.put(y.getDeptId(), y.getDeptName()), HashMap::putAll);
                gzAssessSalaryVos.forEach(x->{
                    x.setEvaluateJobPositions(longStringMap.get(x.getDeptId()));
                });
            }
        }
        return gzAssessSalaryVos;
    }

    /**
     * @Description 通过查询详情VO 用于返回给前端的列详情接口
     * @Author gpframework
     * @Date 2024-01-18
     * @Param [id]
     * @Return GzAssessSalaryVo
     */
    @Override
    public GzAssessSalaryVo getVoById(Long id) {
        return this.baseMapper.getVo(id);
    }
}
